// Source Han Sans 思源黑体-简化版
(function () {
  // 这是一个简化版的字体文件，只包含常用中文字符
  window.sourceHanSansFontBase64 = "AAEAAAAOAIAAAwBgRkZUTXpbx..."; // 这里省略了实际的Base64数据，实际使用时需要完整的字体编码

  // 检查全局对象
  if (
    typeof window.pdfMake !== "undefined" &&
    typeof window.pdfMake.vfs === "undefined"
  ) {
    window.pdfMake.vfs = {};
  }

  // 将字体添加到虚拟文件系统
  if (
    typeof window.pdfMake !== "undefined" &&
    typeof window.pdfMake.vfs !== "undefined"
  ) {
    window.pdfMake.vfs["SourceHanSans-Normal.ttf"] =
      window.sourceHanSansFontBase64;
  }

  // jsPDF兼容
  if (typeof window.jspdf !== "undefined") {
    try {
      var arrayBuffer = base64ToArrayBuffer(window.sourceHanSansFontBase64);
      window.jspdf.addFont(
        "SourceHanSans-Normal.ttf",
        "SourceHanSans-Normal",
        "normal",
        arrayBuffer
      );
    } catch (e) {
      console.error("Failed to add font to jsPDF:", e);
    }
  }

  // Base64 转 ArrayBuffer
  function base64ToArrayBuffer(base64) {
    var binary_string = window.atob(base64);
    var len = binary_string.length;
    var bytes = new Uint8Array(len);
    for (var i = 0; i < len; i++) {
      bytes[i] = binary_string.charCodeAt(i);
    }
    return bytes.buffer;
  }
})();
